/*
 * 天干地支算法
 * 创建：jmdkina@gmail.com
 */
package tgdz
 
import (
    "fmt"
)

var tg = []string{"甲","乙","丙","丁","戊","己","庚","辛","壬", "癸"}
var dz = []string{"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"}

func CalTGDZ(year int) (string) {
    if (year < 4) {
        fmt.Println("year must > 4")
        return ""
    }
    var remainder int
    if (year < (60)) {
        remainder = year-3
    } else {
        remainder = (year-3)%60
    }
    
    var remain int
    if (remainder < 10) {
        remain = remainder
    } else {
        remain = remainder%10
    }
    
    if (remain == 0) {
        remain = 9
    } else {
        remain -= 1
    }
    str1 := tg[remain]
    
    if (remainder < 12) {
        remain = remainder
    } else {
        remain = remainder%12
    }
    if (remain == 0) {
        remain = 11
    } else {
        remain -= 1
    }
    str2 := dz[remain]
    
    return str1 + str2
}
